##use strict;
use HTML::TreeBuilder;
use File::Path;
use Time::Local 'timelocal';
use warnings;
use File::Spec::Functions;
use Cwd;
#use PDL;
my $currentdir= "C:\\FileChangeNotifyTool";

my $SDModifyTime='';
my $MPModifyTime='';

sub initialmodifytime
 {
	my @SD =stat("S:\\China_Product_SW_Update_Schedule_SD.xlsx");
	my @MP =stat("S:\\China_Product_SW_Update_Schedule_MP.xlsx");
	if ($SD[9] ==''){
		my $sendalertsd = $currentdir.'\send_email3.py';
		system($sendalertsd);
		print "Alert Mail Sent\n";
	}
	if ($MP[9] ==''){
		my $sendalertmp = $currentdir.'\send_email3.py';
		system($sendalertmp);
		print "Alert Mail Sent\n";
	}
	$SDModifyTime =$SD[9];
	$MPModifyTime =$MP[9];
	my $sendalertsuccess = $currentdir.'\send_email4.py';
	system($sendalertsuccess);
	print "Initiate success\n\n";
	
 }



sub getSDModifyTime
 {
	my @arraySD = stat("S:\\China_Product_SW_Update_Schedule_SD.xlsx"); 
    #print "SD Create time is $arraySD[8]\n";
    print "SD modify time is $arraySD[9]\n";
	if ($arraySD[9] ==''){
	my $sendalert3 = $currentdir.'\send_email3.py';
	system($sendalert3);
	print "Alert Mail Sent\n";
	next;
	}
	if($SDModifyTime !=$arraySD[9]){
	print "SP File Change\n";
	my $sendalert1 = $currentdir.'\send_email.py';
	system($sendalert1);
	print "Alert Mail Sent\n";
	$SDModifyTime =$arraySD[9];
	}

		
	
}
 



sub	getMPModifyTime
{
   my @arrayMP = stat("S:\\China_Product_SW_Update_Schedule_MP.xlsx"); 
   #print "MP Create time is $arrayMP[8]\n";
   print "MP modify time is $arrayMP[9]\n";
   	if ($arrayMP[9] ==''){
	my $sendalert3 = $currentdir.'\send_email3.py';
	system($sendalert3);
	print "Alert Mail Sent\n";
	next;
	}
	if($MPModifyTime !=$arrayMP[9]){
	print "MP File Change\n";
	my $sendalert2 = $currentdir.'\send_email2.py';
	system($sendalert2);
	print "Alert Mail Sent\n";
	$MPModifyTime =$arrayMP[9];
	}
}


initialmodifytime;
while(1){
sleep 3600;
print "Start Test\n";
getSDModifyTime;
getMPModifyTime;
print "End Test\n\n\n\n";
##sleep 30;
##sleep 7200;
}





  
